package top.honlnk.czuan.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.honlnk.czuan.common.exception.CustomException;
import top.honlnk.czuan.common.result.Result;
import top.honlnk.czuan.pojo.dto.dict.BaiduDictDTO;
import top.honlnk.czuan.pojo.vo.GetBaiduDictVO;
import top.honlnk.czuan.service.DictionaryService;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/dict")
public class DictionaryController {


    @Autowired
    private DictionaryService dictionaryService;

    @GetMapping("/baidu/dict")
    public Result<List<GetBaiduDictVO>> baiduDict(@RequestParam String word) {

        if (word == null) {
            throw new CustomException("单词不可为空");
        }
        BaiduDictDTO baiduDictDTO = new BaiduDictDTO(word, "en", "zh", "");

        // 分析响应的结果
        List<GetBaiduDictVO> getBaiduDictVO = dictionaryService.baiduDict(baiduDictDTO);
        return Result.success(getBaiduDictVO);
    }

    @GetMapping("/baidu/dict/exist")
    public Result<List<GetBaiduDictVO>> baiduDictExist(String word, @RequestParam(defaultValue = "false") Boolean isBlur) {
        if (word == null) {
            throw new CustomException("单词不可为空");
        }
        return Result.success(dictionaryService.isExist(word, isBlur));
    }

    @PostMapping("/baidu/general")
    public Result<String> baiduGeneral(String word, String language) {
        return Result.success();
    }
}
